package com.booklove.service.delivery;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.booklove.domain.dto.PageDTO;
import com.booklove.domain.po.Address;
import com.booklove.domain.query.AddressQuery;
import com.booklove.domain.vo.AddressVO;
import com.booklove.mapper.AddressMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 地址表 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-09-22
 */
@Service
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> implements AddressService {

    @Override
    public PageDTO<AddressVO> queryAddresssPage(AddressQuery addressQuery) {
        // 1.添加排序规则
        // 使用内置的函数转换并且 设置规则
        List<OrderItem> orderItems = addressQuery.toMpOrderItems();

        // 获取分页对象和排序情况
        Page<Address> page = addressQuery.toMpPageDefaultSortByIdAsc(orderItems.toArray(new OrderItem[0]));
        //查询
        Page<AddressVO> p = baseMapper.selectPageVO(page, addressQuery.getName());

        // 获取数据信息
        return PageDTO.of(p, AddressVO.class);
    }
}
